<html>
<head><meta charset="utf-8"><title>static glibc and compiler builtins · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html">static glibc and compiler builtins</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210650050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210650050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210650050">(Sep 20 2020 at 05:13)</a>:</h4>
<p>I'm close to making it possible to statically link glibc on <code>linux-gnu</code> targets. I managed to make the necessary changes to the <code>libc</code> crate, and the only issue left is some linker errors trying to get at symbols that would normally come from <code>libgcc_s</code> when dynamically linking:</p>
<div class="codehilite"><pre><span></span><code>          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(iofclose.o):(.data.rel.local.DW.ref.__gcc_personality_v0[DW.ref.__gcc_personality_v0]+0x0): undefined reference to `__gcc_personality_v0&#39;
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(strtof128_l.o): in function `round_and_return&#39;:
          (.text+0x1d1): undefined reference to `__multf3&#39;
          /usr/bin/ld: (.text+0x227): undefined reference to `__addtf3&#39;
          /usr/bin/ld: (.text+0x36c): undefined reference to `__multf3&#39;
          /usr/bin/ld: (.text+0x400): undefined reference to `__multf3&#39;
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(strtof128_l.o): in function `____strtof128_l_internal&#39;:
          (.text+0x1641): undefined reference to `__multf3&#39;
          /usr/bin/ld: (.text+0x1a95): undefined reference to `__multf3&#39;
          /usr/bin/ld: (.text+0x22f2): undefined reference to `__multf3&#39;
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(strtof128_l.o):(.text+0x24d0): more undefined references to `__multf3&#39; follow
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(printf_fp.o): in function `__printf_fp_l&#39;:
          (.text+0x544): undefined reference to `__unordtf2&#39;
          /usr/bin/ld: (.text+0x57c): undefined reference to `__unordtf2&#39;
          /usr/bin/ld: (.text+0x5a2): undefined reference to `__letf2&#39;
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(printf_fphex.o): in function `__printf_fphex&#39;:
          (.text+0xa3): undefined reference to `__unordtf2&#39;
          /usr/bin/ld: (.text+0xde): undefined reference to `__unordtf2&#39;
          /usr/bin/ld: (.text+0xfb): undefined reference to `__letf2&#39;
          collect2: error: ld returned 1 exit status
</code></pre></div>



<a name="210650154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210650154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210650154">(Sep 20 2020 at 05:17)</a>:</h4>
<p>I could just arrange for an appropriate <code>#[link]</code> line pulling in libgcc when statically linking, or use <code>late_link_args_static</code>.</p>



<a name="210650157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210650157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210650157">(Sep 20 2020 at 05:17)</a>:</h4>
<p>But as far as I can tell, I <em>think</em> that the <em>only</em> reason this actually works is that libstd is built with unwind support, and unwind is unconditionally linking <code>gcc_s</code> on Linux.</p>



<a name="210650253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210650253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210650253">(Sep 20 2020 at 05:20)</a>:</h4>
<p><code>library/unwind/build.rs</code> contains this:</p>
<div class="codehilite"><pre><span></span><code><span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">target</span><span class="p">.</span><span class="n">contains</span><span class="p">(</span><span class="s">&quot;linux&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="n">target</span><span class="p">.</span><span class="n">contains</span><span class="p">(</span><span class="s">&quot;musl&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="c1">// linking for musl is handled in lib.rs</span>
<span class="w">            </span><span class="n">llvm_libunwind</span>::<span class="n">compile</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">!</span><span class="n">target</span><span class="p">.</span><span class="n">contains</span><span class="p">(</span><span class="s">&quot;android&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;cargo:rustc-link-lib=gcc_s&quot;</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="210650568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210650568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210650568">(Sep 20 2020 at 05:31)</a>:</h4>
<p>I think that's the only thing pulling in any part of <code>libgcc</code> in a normal build.</p>



<a name="210654545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210654545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210654545">(Sep 20 2020 at 07:45)</a>:</h4>
<p>I don't think it makes sense to use link args in the target definition here, because you only need libgcc here if you're linking libc and std; programs that use no_std don't need it.</p>



<a name="210654604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210654604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210654604">(Sep 20 2020 at 07:46)</a>:</h4>
<p>I'm also hesitant to use the libc crate's link options to add libgcc and libgcc_eh, because that's assuming you always want to get those functions from there, and not from, say, compiler-builtins.</p>



<a name="210654682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210654682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210654682">(Sep 20 2020 at 07:48)</a>:</h4>
<p>I would really appreciate some help figuring out the right solution for this. Happy to implement whatever it ends up being.</p>



<a name="210660071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210660071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210660071">(Sep 20 2020 at 10:35)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> you have to do something like musl does: <a href="https://github.com/rust-lang/rust/blob/10b3595ba6a4c658c9dea105488fc562c815e434/library/unwind/src/lib.rs#L42">https://github.com/rust-lang/rust/blob/10b3595ba6a4c658c9dea105488fc562c815e434/library/unwind/src/lib.rs#L42</a></p>



<a name="210660136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210660136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210660136">(Sep 20 2020 at 10:37)</a>:</h4>
<p>I've already done that, adding a dependency on gcc_s when dynamic, and gcc_eh when static. But that's part of the unwind crate, and doesn't seem like the right place to insert a dependency on libgcc (as opposed to libgcc_eh).</p>



<a name="210695403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210695403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210695403">(Sep 21 2020 at 01:51)</a>:</h4>
<p>I had a similar issue before. </p>
<p>I wanted to use <code>harfbuzz</code> which depends on <code>fontconfig</code>. </p>
<p>When building the corresponding c library <code>harfbuzz</code>, it needs to know whether the c library <code>fontconfig</code> is built, and locate its c headers.</p>
<p>When using the prebuilt library of c library <code>harfbuzz</code>, since it's already including c library <code>fontconfig</code> as a dependency, it should somehow tell the <code>fontconfig</code> library to use the already prebuilt <code>fontconfig</code> along side the c library <code>harfbuzz</code>.</p>
<p>So i guess this is "dependency crate wants to fine-tune the details of how the crates it depends on does ffi"</p>



<a name="210695458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210695458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210695458">(Sep 21 2020 at 01:53)</a>:</h4>
<p>In theory we might be able to workaround this with a lot of "feature"s on the crate that was depended upon (which i think will work, but a little too hacky).</p>



<a name="210695508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210695508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210695508">(Sep 21 2020 at 01:54)</a>:</h4>
<p>I was also imagining that the <code>metabuild</code> mechanism can somehow see the whole crate graph and help decide what the correct configuration would be.</p>



<a name="210696391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210696391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210696391">(Sep 21 2020 at 02:19)</a>:</h4>
<p>I just filed <a href="https://github.com/rust-lang/rust/issues/76992">https://github.com/rust-lang/rust/issues/76992</a> , which should help with part of this.</p>



<a name="210696392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210696392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210696392">(Sep 21 2020 at 02:19)</a>:</h4>
<p>I think I can solve the rest.</p>



<a name="210710458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210710458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210710458">(Sep 21 2020 at 07:53)</a>:</h4>
<p>I think hack like this one would help you: <a href="https://github.com/rust-lang/rust/blob/a409a233e02b1864d1b76495a1f946bb56c7aeb2/compiler/rustc_target/src/spec/windows_gnu_base.rs#L37-L63">https://github.com/rust-lang/rust/blob/a409a233e02b1864d1b76495a1f946bb56c7aeb2/compiler/rustc_target/src/spec/windows_gnu_base.rs#L37-L63</a><br>
But AFAIK it will also link those libs for <code>no_std</code> programs which is bad.</p>



<a name="210711114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711114">(Sep 21 2020 at 08:02)</a>:</h4>
<p><span class="user-mention" data-user-id="119581">@mati865</span> That's where I ended up, but yeah, it's not ideal.</p>



<a name="210711146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711146">(Sep 21 2020 at 08:03)</a>:</h4>
<p>On the other hand, in practice those libraries will get completely omitted if unused.</p>



<a name="210711229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711229">(Sep 21 2020 at 08:04)</a>:</h4>
<p>The other alternative I could imagine would be to embed the knowledge of which libraries to link in the <code>libc</code> crate, and then that crate would have to change if we ever decided to move those functions from libgcc to compiler-builtins.</p>



<a name="210711406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711406">(Sep 21 2020 at 08:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins/near/210711146">said</a>:</p>
<blockquote>
<p>On the other hand, in practice those libraries will get completely omitted if unused.</p>
</blockquote>
<p>I imagine they would be an issue when used tries to manually implement  symbols from them (again for <code>no_std</code>).<br>
It's not that big deal on Windows where <code>no_std</code> basically doesn't work yet but on Unix this is scary.</p>



<a name="210711766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711766">(Sep 21 2020 at 08:10)</a>:</h4>
<p>Fair enough.</p>



<a name="210711803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711803">(Sep 21 2020 at 08:11)</a>:</h4>
<p>Do you think it'd be a reasonably un-painful transition to move from libc pulling in gcc and gcc_eh to wanting to use compiler-builtins instead, if we want to change that in the future?</p>



<a name="210711819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210711819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210711819">(Sep 21 2020 at 08:11)</a>:</h4>
<p>Because if so, I can easily just add those two libraries to the libc crate and be done with it. :)</p>



<a name="210712067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712067">(Sep 21 2020 at 08:15)</a>:</h4>
<p>You mean replacing libgcc with compiler-builtins and libgcc_eh with libunwind?</p>



<a name="210712117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712117">(Sep 21 2020 at 08:15)</a>:</h4>
<p>Aren't we already using compiler-builtins on linux-gnu, and just not implementing all the functions libgcc does?</p>



<a name="210712137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712137">(Sep 21 2020 at 08:16)</a>:</h4>
<p>But in any case, yes, something like that for instance. :)</p>



<a name="210712207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712207">(Sep 21 2020 at 08:17)</a>:</h4>
<p>I can imagine ways to make that transition easily enough.</p>



<a name="210712224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712224">(Sep 21 2020 at 08:17)</a>:</h4>
<blockquote>
<p>Aren't we already using compiler-builtins on linux-gnu, and just not implementing all the functions libgcc does?</p>
</blockquote>
<p>AFAIK we are doing that for Rust code but not for other libraries.</p>



<a name="210712240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712240">(Sep 21 2020 at 08:17)</a>:</h4>
<p>Ah. OK, then this seems reasonable enough.</p>



<a name="210712247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712247">(Sep 21 2020 at 08:17)</a>:</h4>
<p>I'll try doing it that way and see how well it works.</p>



<a name="210712647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712647">(Sep 21 2020 at 08:23)</a>:</h4>
<p>I'd love to use compiler-builtins and libunwind more so we have no dependencies on libgcc*.<br>
On <code>i686-*-windows-gnu</code> we have to use either <code>libgcc_s_dw2-1.dll</code> (linked by <code>gcc_s</code> import library) or <code>libunwind.dll</code>, otherwise exception handling will break. For all other targets I care about (<code>*linux*</code> and  <code>*windows-gnu*</code>) this should work fine.</p>



<a name="210712746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210712746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210712746">(Sep 21 2020 at 08:24)</a>:</h4>
<p>Well, if in the future we want to get there, the libc crate could always update to have a feature flag for "omit gcc libraries in favor of compiler builtins", and avoid emitting the <code>#[link</code> directives for those libraries in that case.</p>



<a name="210713097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713097">(Sep 21 2020 at 08:29)</a>:</h4>
<p>Sounds good :D</p>



<a name="210713299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713299">(Sep 21 2020 at 08:31)</a>:</h4>
<p>As an aside, I feel like the whole <code>target-feature=+crt-static</code> mechanism is a lot of special-casing of the C library. It seems like, in general, the top-level crate should be able to decide whether it's linking statically or dynamically, and dependency crates should mostly just say "I want the <code>foo</code> library" unless they actually need to link different libraries for the static and dynamic cases.</p>



<a name="210713395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713395">(Sep 21 2020 at 08:32)</a>:</h4>
<p>I'd love to mostly just pass <code>-lfoo -lbar</code> on the linker command line, from the various crates, and <em>just</em> pass rustc one option that tells it to pass <code>-static</code> (or <code>-Wl,-Bstatic</code>), without needing things like cargo feature flags in individual library crates.</p>



<a name="210713412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713412">(Sep 21 2020 at 08:32)</a>:</h4>
<p>I don't think it should be up to the individual cargo crates whether they want to link statically or dynamically, in the common case. (In uncommon cases, sure, they <em>could</em> control it, but they shouldn't have to always map a feature flag to this, they should get information from the top-level build for what kind of linking it intends to do.)</p>



<a name="210713536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713536">(Sep 21 2020 at 08:34)</a>:</h4>
<p>In any case, just managed to successfully build a static glibc-based binary using the libc-crate-based approach. Now to submit patches...</p>



<a name="210713603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713603">(Sep 21 2020 at 08:35)</a>:</h4>
<p>I'll submit the rust-lang/rust patches as soon as <a href="https://github.com/rust-lang/libc/pull/1899">https://github.com/rust-lang/libc/pull/1899</a> gets merged into libc and released.</p>



<a name="210713698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210713698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210713698">(Sep 21 2020 at 08:36)</a>:</h4>
<p><span class="user-mention" data-user-id="119581">@mati865</span> Thanks for talking through the problem with me; I appreciate it.</p>



<a name="210714053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210714053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210714053">(Sep 21 2020 at 08:40)</a>:</h4>
<p>As an intermediate step, would you mind reviewing <a href="https://github.com/rust-lang/rust/pull/77003">https://github.com/rust-lang/rust/pull/77003</a> ?</p>



<a name="210714745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210714745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210714745">(Sep 21 2020 at 08:50)</a>:</h4>
<p>IIRC when <code>crt-static</code> was introduced the only "normal" static target was <code>*linux-musl</code> and it could not link dynamically. Things were a bit different back then but I do agree with "the top-level crate should be able to decide whether it's linking statically or dynamically".</p>
<blockquote>
<p>I'd love to mostly just pass <code>-lfoo -lbar</code> on the linker command line, from the various crates, and <em>just</em> pass rustc one option that tells it to pass <code>-static</code> (or <code>-Wl,-Bstatic</code>), without needing things like cargo feature flags in individual library crates.</p>
</blockquote>
<p>I think this should be still doable.</p>
<blockquote>
<p>As an intermediate step, would you mind reviewing <a href="https://github.com/rust-lang/rust/pull/77003">https://github.com/rust-lang/rust/pull/77003</a> ?</p>
</blockquote>
<p>I'll take a look but I'm not one to make the decision here.</p>



<a name="210716667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/static%20glibc%20and%20compiler%20builtins/near/210716667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/static.20glibc.20and.20compiler.20builtins.html#210716667">(Sep 21 2020 at 09:11)</a>:</h4>
<p><a href="https://github.com/rust-lang/libc/pull/1899">https://github.com/rust-lang/libc/pull/1899</a> would be more readable if it was done with a macro ;)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>